DateAdd (intervalType, nIntervals, startDateTime)

Basic and Crystal syntax.

Arguments

intervalType is a String expression specifying the interval of time to be added. Values can be:

IntervalType value Description

yyyy

Year

q

Quarter (3-month period)

m

Month

y

Day of year

d

Day

w

Weekday

ww

Week (7-day period)

h

Hour

n

Minute

s

Second

Returns

A DateTime value.

Action

DateAdd returns a DateTime value to which a specified number of time intervals have been added.

Typical use

DateAdd is used to add intervals of time to a DateTime. Its main feature is that the DateTime returned will always be valid. For example, DateAdd takes into account such factors as the number of days in a month and leap years. If you want to add or subtract days to a DateTime, you could use the addition and subtraction operators instead of DateAdd with the "d" parameter. However, DateAdd also handles other types of intervals such as adding months or hours to a DateTime.

Examples

The following examples are applicable to both Basic and Crystal syntax:

DateAdd("d", -32, #Sept 28, 1999#)

Returns the DateTime value for August 27, 1999.

DateAdd ("m", 1, #1/31/1996#)

Returns the DateTime value for February 29, 1996. Notice that DateAdd will not return the invalid value February 31, 1996.

DateAdd ("q", 17, #Sept 28, 1999#)

Returns the DateTime value for December 28, 2003.

DateAdd ("h", -400, #Sept 28, 1999#)

Returns the DateTime value for September 11, 1999 8:00 AM. In other words, this is the result of subtracting 400 hours from September 28, 1999 12:00 AM.

Comments

CDate(DateAdd("yyyy", -2, #October 6, 1999#))



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com